<?php
include( "admin/now5_header.php" );
$percent = 0;
$lostwin = array();
$betcount = array();
$totalamount = array();
$list = array();
$betids = array(7, 8, 9, 10, 11,48);
foreach ($betids as $bettype)
{
    $totalamount[$bettype] = 0;
    $betcount[$bettype] = 0;
    $list[$bettype] = "";
    $betTypeStr = "bettype=" . $bettype;
    $sql = " sum(totalAmt) as totalAmt FROM (\r\n  Select line_nums,(unitmoney*upercent/100) as totalAmt\r\n  from bet where {$betTypeStr} and lotto_id={$lotto_id} and rame in (0,9) \r\n  UNION ALL\r\n  Select line_nums,(unitmoney*percent255/100) as totalAmt\r\n  from bet2 where {$betTypeStr} and lotto_id={$lotto_id} and rame in (0,9) \r\n  UNION ALL\r\n  Select line_nums,(amount*-1) as totalAmt\r\n  from bet8 where {$betTypeStr} and lotto_id={$lotto_id} and rame in (0,9) \r\n  ) A";
    $rs1 = getdb("SELECT " . $sql);
    $rs2 = getdb("Select line_nums," . $sql . " GROUP BY line_nums Order by totalAmt desc LIMIT 20");
    $totalamount[$bettype] = round($rs1->f[0], 0);
    while (!$rs2->eof && $totalamount[$bettype] != 0)
    {
        $c = $rs2->f[0];
        $n = round($rs2->f[1], 0);
        if ($c != "" && $n != 0)
        {
            $list[$bettype] .= "<tr align=center>";
            $list[$bettype] .= "<td nowrap><a href=" . get_listurl5($open, $bettype, $c) . ">" . $c . "</a></td>";
            $list[$bettype] .= "<td nowrap align=right><font color=#0000A8><b>" . $n . "</b></font></td></tr>";
        }
        $rs2->movenext();
    }
}
$rs1->close();
$rs2->close();
$tpl->set("money48", $totalamount[48]);
$tpl->set("money08", $totalamount[8]);
$tpl->set("money09", $totalamount[9]);
$tpl->set("money07", $totalamount[7]);
$tpl->set("money10", $totalamount[10]);
$tpl->set("money11", $totalamount[11]);
$tpl->set("list48", $list[48]);
$tpl->set("list8", $list[8]);
$tpl->set("list9", $list[9]);
$tpl->set("list7", $list[7]);
$tpl->set("list10", $list[10]);
$tpl->set("list11", $list[11]);
$rs8 = getdb("select * from rate8 where lotto_id={$lotto_id} and disk=1");
if ($rs8->eof)
{
    $ui->showErrorPage("<p class=error>系统目前维护中(三全中无赔率)，请稍後！</p>");
    exit();
}
$rate8Arr = array();
$i = 1;
while ($i < 50)
{
    $rate8Arr["r8_{$i}"] = intval($rs8->f["r" . d2($i)]);
    ++$i;
}
sort($rate8Arr);
$rs8->close();
$tpl->set("r8_hi", $rate8Arr[48]);
$tpl->set("r8_lo", $rate8Arr[0]);
$rs9 = getdb("select * from rate9 where lotto_id={$lotto_id} and disk=1");
if ($rs9->eof)
{
    $ui->showErrorPage("<p class=error>系统目前维护中(四全中无赔率)，请稍後！</p>");
    exit();
}
$rate9Arr = array();
$i = 1;
while ($i < 50)
{
    $rate9Arr["r9_{$i}"] = intval($rs9->f["r" . d2($i)]);
    ++$i;
}
sort($rate9Arr);
$rs9->close();
$tpl->set("r48_hi", $rate9Arr[48]);
$tpl->set("r48_lo", $rate9Arr[0]);

$rs = getdb("select * from rate5a where lotto_id=" . $lotto_id);
if ($rs->eof)
{
    $ui->showErrorPage("<p class=error>系统目前维护中，请稍後！</p>");
    exit();
}
$tpl->set("r9_1", $rs->f['r9_1']);
$tpl->set("r9_2", $rs->f['r9_2']);
$tpl->set("r7_1", $rs->f['r7_1']);
$tpl->set("r10_1", $rs->f['r10_1']);
$tpl->set("r10_2", $rs->f['r10_2']);
$tpl->set("r11_1", $rs->f['r11_1']);
$tpl->load("main", "now5.htm");
$tpl->show("main");
$ui->footer();
?>